package de.koller.million.render.obj;

import de.koller.million.render.RenderRoot;
import de.koller.oceanFramework.gl.util.ParticleTexture;
import de.koller.oceanFramework.gl.util.TextureUtil;
import de.koller.oceanFramework.tree.Mother;
import de.koller.oceanFramework.tree.Sea3X;
import org.lwjgl.opengl.GL11;

public class Floor extends Sea3X {
	
	@Mother private RenderRoot rroot;
	private ParticleTexture texture;
	private int mipmap;
	
	@Override
	protected void init() {
		super.init();
		
		ParticleTexture.MIN_FILTER = GL11.GL_LINEAR;
		ParticleTexture.MAG_FILTER = GL11.GL_LINEAR;
		texture = ParticleTexture.generate( 64, 64 );
		texture.clear( 0xff000000 );
		for( int i = 0; i < 64; i++ ) {
			texture.setPixel( 0xffffffff, i, 0 );
			texture.setPixel( 0xffffffff, 0, i );
			texture.setPixel( 0xffffffff, i, 63 );
			texture.setPixel( 0xffffffff, 63, i);
		}
				
		texture.flush();
		
		TextureUtil.MAG_FILTER = GL11.GL_LINEAR;
		mipmap = TextureUtil.makeMipMap( texture );
		
		TextureUtil.delete( texture.getTextureID() );
	}

	@Override
	protected void render( int elapsedTime ) {
		super.render( elapsedTime );

		if( rroot.getRenderIteration() == 1 )
			return;
		
		TextureUtil.bind( mipmap );
		
		GL11.glColor3f( 1, 1, 1 );
		GL11.glBegin( GL11.GL_QUADS );
			GL11.glNormal3f( 0, 1, 0 );
			GL11.glTexCoord2f( 0, 0 );
			GL11.glVertex3f( -10, 0, -10 );
			
			GL11.glTexCoord2f( 0, 20 );
			GL11.glVertex3f( -10, 0, 10 );
			
			GL11.glTexCoord2f( 20, 20 );
			GL11.glVertex3f( 10, 0, 10 );
			
			GL11.glTexCoord2f( 20, 0 );
			GL11.glVertex3f( 10, 0, -10 );
		GL11.glEnd();	
	}
	
	
	
}
